// #pragma once

#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

#include "LED.h"
#include "application.h"
#include "Hardward.h"




osThreadId LEDTaskHandle;
osThreadId ApplicationTaskHandle;
osThreadId HardwardTaskHandle;

void StartLEDTASK(void const *argument);
void StartApplicationTASK(void const *argument);
void StartHardwardTASK(void const *argument);


/**
 * @brief 初始化所有任务,所有持续运行的任务都在这里初始化
 *
 */
void OSTaskInit()
{
    osThreadDef(Hardwardtask,StartHardwardTASK,osPriorityNormal,0,32);
    HardwardTaskHandle = osThreadCreate(osThread(Hardwardtask),NULL);

    osThreadDef(Applicationtask, StartApplicationTASK, osPriorityNormal, 0, 200);
    ApplicationTaskHandle = osThreadCreate(osThread(Applicationtask), NULL);

    osThreadDef(LEDtask, StartLEDTASK, osPriorityNormal, 0, 16);
    LEDTaskHandle = osThreadCreate(osThread(LEDtask), NULL);

}


/**
 * @brief 点灯测试程序，检验代码是否正常运行
 */
__attribute__((noreturn)) void StartLEDTASK(void const *argument)
{
    // LOGINFO("[freeRTOS] LED Task Start");
    // LEDInit();
    // LOGINFO("[freeRTOS] LED Init Done, communication with ref has established");
    for (;;)
    {
    LEDTask();
    osDelay(100);
    }
}
/**
 * @brief OLED显示代码，显示人机交互的数据
 */
__attribute__((noreturn)) void StartApplicationTASK(void const *argument)
{
    ApplicationInit();
    for (;;)
    {
    ApplicationTask();
    osDelay(50);
    }
}
/**
 * @brief 用户的基础数据更新，包括按键，ADC，蜂鸣器
 */
__attribute__((noreturn)) void StartHardwardTASK(void const *argument)
{
    Hardward_Init();
    for (;;)
    {
    Hardward_Task();
    osDelay(20);
    }
}


